﻿//-----------------------------------------------------------------------
// <copyright file="SettingsWindowViewModel.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.UI.Windows.Settings
{
    using System.Windows.Input;

    using ChatBox.DomainObjects.Settings;
    using ChatBox.Interfaces;
    using ChatBox.UI.Commands;
    using ChatBox.UI.Themes;
    using ChatBox.UI.ViewModels;

    /// <summary>
    /// View model for settings data window
    /// </summary>
    public class SettingsWindowViewModel : WindowViewModel
    {
        /// <summary>
        ///  source of login data
        /// </summary>
        private readonly ILogOnSource logOnSource;

        /// <summary>
        /// the command to close the window without saving
        /// </summary>
        private readonly ICommand closeCommand;

        /// <summary>
        /// the command to save and close the window
        /// </summary>
        private readonly ICommand saveCommand;

        /// <summary>
        /// Status of log on
        /// </summary>
        private readonly string logOnStatus;

        /// <summary>
        /// Initializes a new instance of the SettingsWindowViewModel class
        /// </summary>
        /// <param name="logOnSource">source for logon data</param>
        /// <param name="themeManager">the theme manager to use</param>
        /// <param name="closeCommand">the command to close the window without saving</param>
        /// <param name="saveCommand">the command to save and close the window</param>
        public SettingsWindowViewModel(ILogOnSource logOnSource, ThemeManager themeManager, WindowCloseCommand closeCommand, SaveSettingsCommand saveCommand)
        {
            this.ThemeManager = themeManager;
            this.logOnSource = logOnSource;
            this.closeCommand = closeCommand;
            this.saveCommand = saveCommand;

            if (this.logOnSource.LogOnCookie == null)
            {
                this.logOnStatus = "Not logged in";
            }
            else
            {
                this.logOnStatus = "Logged in";                
            }
        }

        /// <summary>
        /// Gets or sets the ServerSettings
        /// </summary>
        public ServerSettingsData ServerSettings { get; set; }

        /// <summary>
        /// Gets or sets the Ui settings
        /// </summary>
        public UISettingsData UISettings { get; set; }

        /// <summary>
        /// Gets the current theme data
        /// </summary>
        public ThemeManager ThemeManager { get; private set; }

        /// <summary>
        /// Gets the command to close the window
        /// </summary>
        public ICommand CloseCommand
        {
            get { return this.closeCommand; }
        }

        /// <summary>
        /// Gets the command to save and close the window
        /// </summary>
        public ICommand SaveCommand
        {
            get { return this.saveCommand; }
        }

        /// <summary>
        /// Gets or sets the command to notify the application of settings change
        /// </summary>
        public ICommand NotifyApplicationOfSettingsChange { get; set; }

        /// <summary>
        /// Gets or sets the smallest interval for public chat refresh
        /// </summary>
        public double MinPublicChatRefreshInterval { get; set; }

        /// <summary>
        /// Gets or sets the largest interval for public chat refresh
        /// </summary>
        public double MaxPublicChatRefreshInterval { get; set; }

        /// <summary>
        /// Gets or sets the smallest interval for private chat refresh
        /// </summary>
        public double MinPrivateChatRefreshInterval { get; set; }

        /// <summary>
        /// Gets or sets the largest interval for private chat refresh
        /// </summary>
        public double MaxPrivateChatRefreshInterval { get; set; }

        /// <summary>
        /// Gets or sets the smallest interval for other users refresh
        /// </summary>
        public double MinOtherUsersRefreshInterval { get; set; }

        /// <summary>
        /// Gets or sets the largest interval for other users refresh
        /// </summary>
        public double MaxOtherUsersRefreshInterval { get; set; }

        /// <summary>
        /// Gets the state of the login
        /// </summary>
        public string LogOnStatus
        {
            get { return this.logOnStatus; }
        }
    }
}